<template>
<div>
  <router-link
    tag="div"
    to="/"
    class="header-abs"
    v-show="showAbs"
  >
    <span class="iconfont header-abs-back">&#xe61e;</span>
  </router-link>
  <div class="header-fixed"
    v-show="!showAbs"
    :style="opacityStyle"
  >
    <router-link to="/">
      <span class="iconfont back-btn">&#xe61e;</span>
    </router-link>
    景点详情
  </div>
</div>
</template>

<script>
export default {
  name: 'DetailHeader',
  data() {
    return {
      showAbs: true,
      opacityStyle: {
        opacity: 0,
      },
    };
  },
  components: {

  },
  activated() {
    window.addEventListener('scroll', this.handleScroll);
  },
  deactivated() {
    // 解绑全局事件
    window.removeEventListener('scroll', this.handleScroll);
  },
  methods: {
    handleScroll() {
      const top = document.documentElement.scrollTop;

      if (top > 60) {
        let opacity = top / 140;
        opacity = opacity > 1 ? 1 : opacity;
        this.opacityStyle = { opacity };
        this.showAbs = false;
      } else {
        this.showAbs = true;
      }
    },
  },
};
</script>

<style lang="stylus" scoped>
  @import '~style/varibles.styl'
  .header-fixed
    position : fixed
    top: 0
    left: 0
    right: 0
    overflow: hidden
    height: $headerHeight
    line-height: $headerHeight
    text-align : center
    color: #ffffff
    background : $bgColor
    font-size : 4vw
    z-index : 9
    .back-btn
      position: absolute
      left: 0
      top: 0
      padding:0 1vw
      color:#fff
  .header-abs
    position: absolute;
    display: block;
    left: 1vw;
    top: 1vw;
    width: 10vw;
    height: 10vw;
    line-height: 10vw;
    background: rgba(0,0,0,0.8);
    z-index: 9;
    border-radius: 5vw;
    text-align: center;
    .header-abs-back
      color : #ffffff
      font-size : 6vw
</style>
